﻿#pragma once

#include "stdafx.h"
#include "Util.h"

#ifdef _DEBUG
//显示结点区域
//#define SHOW_NODE_REGION
#endif

// Node Types
#define NT_STANDARD						_T("NT_STANDARD")						// standard-node
#define NT_INPLACE						_T("NT_INPLACE")						// inplaced node
#define NT_SIGN							_T("NT_SIGN")							// sign node
#define NT_GREEKALPHABET				_T("NT_GREEKALPHABET")					// greek alphabet
#define NT_ALPHABET						_T("NT_ALPHABET")						// alphabet
#define NT_HANDWRITING					_T("NT_HANDWRITING")					// handwriting
#define NT_COPPERPLATE					_T("NT_COPPERPLATE")					// copperplate

#define NT_PLUS							_T("NT_PLUS")							// x + y
#define NT_MINUS						_T("NT_MINUS")							// x - y
#define NT_MULTIPLY						_T("NT_MULTIPLY")						// x * y
#define NT_DIVIDE						_T("NT_DIVIDE")							// x / y
#define NT_EQUATION						_T("NT_EQUATION")						// equations =

#define NT_HYPHEN						_T("NT_HYPHEN")							// -
#define NT_DOT							_T("NT_DOT")							// ·
#define NT_LESSTHANOREQUAL				_T("NT_LESSTHANOREQUAL")				// ≤
#define NT_GREATERTHANOREQUAL			_T("NT_GREATERTHANOREQUAL")				// ≥
#define NT_EQUAL						_T("NT_EQUAL")							// =
#define NT_LESSTHAN						_T("NT_LESSTHAN")						// <
#define NT_GREATERTHAN					_T("NT_GREATERTHAN")					// >
#define NT_NOTEQUAL						_T("NT_NOTEQUAL")						// ≠
#define NT_PERCENT						_T("NT_PERCENT")						// %
#define NT_SLASH						_T("NT_SLASH")							// /
#define NT_BACKSLASH					_T("NT_BACKSLASH")						// \-
#define NT_SINGLEQUOTE					_T("NT_SINGLEQUOTE")					// '
#define NT_COLON						_T("NT_COLON")							// :
#define NT_DOUBLEQUOTE					_T("NT_DOUBLEQUOTE")					// "
#define NT_AND							_T("NT_AND")							// &
#define NT_STAR							_T("NT_STAR")							// *
#define NT_HASHKEY						_T("NT_HASHKEY")						// #
#define NT_QUESTIONMARK					_T("NT_QUESTIONMARK")					// ?
#define NT_SEMICOLON					_T("NT_SEMICOLON")						// ;
#define NT_VERTICALBAR					_T("NT_VERTICALBAR")					// |
#define NT_EXCLAMATIONMARK				_T("NT_EXCLAMATIONMARK")				// !
#define NT_LEFTPARENTHESIS				_T("NT_LEFTPARENTHESIS")				// (
#define NT_RIGHTPARENTHESIS				_T("NT_RIGHTPARENTHESIS")				// )
#define NT_LEFTBRACKET					_T("NT_LEFTBRACKET")					// [
#define NT_RIGHTBRACKET					_T("NT_RIGHTBRACKET")					// ]
#define NT_LEFTBRACE					_T("NT_LEFTBRACE")						// {
#define NT_RIGHTBRACE					_T("NT_RIGHTBRACE")						// }
#define NT_TILDE						_T("NT_TILDE")							// ~
#define NT_PERIOD						_T("NT_PERIOD")							// .
#define NT_ISEQUIVALENTTO				_T("NT_ISEQUIVALENTTO")					// ≡
#define NT_PLUSORMINUS					_T("NT_PLUSORMINUS")					// ±
#define NT_COMMA						_T("NT_COMMA")							// ,
#define NT_ISAPPROXIMATELYEQUALTO		_T("NT_ISAPPROXIMATELYEQUALTO")			// ≈
#define NT_INFINITY						_T("NT_INFINITY")						// ∞
#define NT_SINGLERIGHTARROW				_T("NT_SINGLERIGHTARROW")				// →
#define NT_SINCE						_T("NT_SINCE")							// ∵
#define NT_HENCE						_T("NT_HENCE")							// ∴
#define NT_BELONGTO						_T("NT_BELONGTO")						// ∈
#define NT_CONTAIN						_T("NT_CONTAIN")						// ⊂
#define NT_INCLUSION					_T("NT_INCLUSION")						// ⊆
#define NT_UNIONOF						_T("NT_UNIONOF")						// ∪
#define NT_INTERSECTIONOF				_T("NT_INTERSECTIONOF")					// ∩
#define NT_DELTA						_T("NT_DELTA")							// ∂
#define NT_NABLA						_T("NT_NABLA")							// ▽
#define NT_VARIESAS						_T("NT_VARIESAS")						// ∝
#define NT_PROPOSITIONALNEGATION		_T("NT_PROPOSITIONALNEGATION")			// ﹁
#define NT_UNIVERSALQUANTIFIER			_T("NT_UNIVERSALQUANTIFIER")			// ∀
#define NT_DOUBLERIGHTARROW				_T("NT_DOUBLERIGHTARROW")				// ⇒
#define NT_EXISTENTIALQUANTIFIER		_T("NT_EXISTENTIALQUANTIFIER")			// ∃
#define NT_PLANCKCONSTANT				_T("NT_PLANCKCONSTANT")					// ћ

#define NT_LIM							_T("NT_LIM")							// lim
#define NT_MIN							_T("NT_MIN")							// min
#define NT_MAX							_T("NT_MAX")							// max
#define NT_LIMIT						_T("NT_LIMIT")							// limit
#define NT_MINIMUM						_T("NT_MINIMUM")						// minimum
#define NT_MAXIMUM						_T("NT_MAXIMUM")						// maximum

#define NT_LOG							_T("NT_LOG")							// log
#define NT_LN							_T("NT_LN")								// ln
#define NT_LG							_T("NT_LG")								// lg
#define NT_LOGARITHM					_T("NT_LOGARITHM")						// logarithm

#define NT_NOTIN						_T("NT_NOTIN")							// ∉
#define NT_NSUBSETEQ					_T("NT_NSUBSETEQ")						// ⊈
#define NT_EMPTYSET						_T("NT_EMPTYSET")						// Ø
#define NT_LEFTRIGHTARROW				_T("NT_LEFTRIGHTARROW")					// ⇔
#define NT_MAPSTO						_T("NT_MAPSTO")							// ↦
#define NT_epsilon						_T("NT_epsilon")						// ϵ
#define NT_ALEPH						_T("NT_ALEPH")							// ℵ
#define NT_varrho						_T("NT_varrho")							// ϱ
#define NT_BOXMINUS						_T("NT_BOXMINUS")						// ⊟
#define NT_BOXTIMES						_T("NT_BOXTIMES")						// ⊠
#define NT_BOXDOT						_T("NT_BOXDOT")							// ⊡
#define NT_BOXPLUS						_T("NT_BOXPLUS")						// ⊞
#define NT_OMINUS						_T("NT_OMINUS")							// ⊖
#define NT_CIRCLEDDASH					_T("NT_CIRCLEDDASH")					// ⊝
#define NT_OPLUS						_T("NT_OPLUS")							// ⊕
#define NT_OTIMES						_T("NT_OTIMES")							// ⊗
#define NT_OSLASH						_T("NT_OSLASH")							// ⊘
#define NT_ODOT							_T("NT_ODOT")							// ⊙
#define NT_CIRCLEDCIRC					_T("NT_CIRCLEDCIRC")					// ⊚
#define NT_CIRCLEDAST					_T("NT_CIRCLEDAST")						// ⊛
#define NT_BIGODOT						_T("NT_BIGODOT")						// ⨀
#define NT_BIGOTIMES					_T("NT_BIGOTIMES")						// ⨂
#define NT_BIGOPLUS						_T("NT_BIGOPLUS")						// ⨁

#define NT_SUPERSCRIPT					_T("NT_SUPERSCRIPT")					// x power of y
#define NT_SUBSCRIPT					_T("NT_SUBSCRIPT")						// subscript
#define NT_MIDTOPBOTTOM					_T("NT_MIDTOPBOTTOM")					//
#define NT_TOPBOTTOMMID					_T("NT_TOPBOTTOMMID")					//

#define NT_RADICAL						_T("NT_RADICAL")						// radical expression

#define NT_PARENTHESES					_T("NT_PARENTHESES")					// ()
#define NT_BRACKETS						_T("NT_BRACKETS")						// []
#define NT_BRACES						_T("NT_BRACES")							// {}
#define NT_ABSOLUTE						_T("NT_ABSOLUTE")						// ||
#define NT_SEPARATOR					_T("NT_SEPARATOR")						// separator

#define NT_INTEGRAL						_T("NT_INTEGRAL")						// integral
#define NT_INTEGRALTBLIMIT				_T("NT_INTEGRALTBLIMIT")				// integral
#define NT_INTEGRALTBSCRIPT				_T("NT_INTEGRALTBSCRIPT")				// integral
#define NT_DOUBLEINTEGRAL				_T("NT_DOUBLEINTEGRAL")					// double integral
#define NT_DOUBLEINTEGRALTBLIMIT		_T("NT_DOUBLEINTEGRALTBLIMIT")			// double integral
#define NT_DOUBLEINTEGRALTBSCRIPT		_T("NT_DOUBLEINTEGRALTBSCRIPT")			// double integral
#define NT_TRIPLEINTEGRAL				_T("NT_TRIPLEINTEGRAL")					// triple integral
#define NT_TRIPLEINTEGRALTBLIMIT		_T("NT_TRIPLEINTEGRALTBLIMIT")			// triple integral
#define NT_TRIPLEINTEGRALTBSCRIPT		_T("NT_TRIPLEINTEGRALTBSCRIPT")			// triple integral
#define NT_LOOPINTEGRAL					_T("NT_LOOPINTEGRAL")					// loop integral
#define NT_LOOPINTEGRALTBLIMIT			_T("NT_LOOPINTEGRALTBLIMIT")			// loop integral
#define NT_LOOPINTEGRALTBSCRIPT			_T("NT_LOOPINTEGRALTBSCRIPT")			// loop integral
#define NT_DOUBLELOOPINTEGRAL			_T("NT_DOUBLELOOPINTEGRAL")				// double loop integral
#define NT_DOUBLELOOPINTEGRALTBLIMIT	_T("NT_DOUBLELOOPINTEGRALTBLIMIT")		// double loop integral
#define NT_DOUBLELOOPINTEGRALTBSCRIPT	_T("NT_DOUBLELOOPINTEGRALTBSCRIPT")		// double loop integral
#define NT_TRIPLELOOPINTEGRAL			_T("NT_TRIPLELOOPINTEGRAL")				// triple loop integral
#define NT_TRIPLELOOPINTEGRALTBLIMIT	_T("NT_TRIPLELOOPINTEGRALTBLIMIT")		// triple loop integral
#define NT_TRIPLELOOPINTEGRALTBSCRIPT	_T("NT_TRIPLELOOPINTEGRALTBSCRIPT")		// triple loop integral

#define NT_SUM							_T("NT_SUM")							// Sum from i=0;to i=10, over fkt(i)
#define NT_SUMTBLIMIT					_T("NT_SUMTBLIMIT")						// Sum from i=0;to i=10, over fkt(i)
#define NT_SUMTBSCRIPT					_T("NT_SUMTBSCRIPT")					// Sum from i=0;to i=10, over fkt(i)
#define NT_SUMBLIMIT					_T("NT_SUMBLIMIT")						// Sum from i=0;to i=10, over fkt(i)
#define NT_SUMBSCRIPT					_T("NT_SUMBSCRIPT")						// Sum from i=0;to i=10, over fkt(i)
#define NT_SUPREMUM						_T("NT_SUPREMUM")						// 上确界（序理论的基础概念之一）
#define NT_SUPREMUMTBLIMIT				_T("NT_SUPREMUMTBLIMIT")				// 上确界（序理论的基础概念之一）
#define NT_SUPREMUMTBSCRIPT				_T("NT_SUPREMUMTBSCRIPT")				// 上确界（序理论的基础概念之一）
#define NT_SUPREMUMBLIMIT				_T("NT_SUPREMUMBLIMIT")					// 上确界（序理论的基础概念之一）
#define NT_SUPREMUMBSCRIPT				_T("NT_SUPREMUMBSCRIPT")				// 上确界（序理论的基础概念之一）
#define NT_INFIMUM						_T("NT_INFIMUM")						// 下确界
#define NT_INFIMUMTBLIMIT				_T("NT_INFIMUMTBLIMIT")					// 下确界
#define NT_INFIMUMTBSCRIPT				_T("NT_INFIMUMTBSCRIPT")				// 下确界
#define NT_INFIMUMBLIMIT				_T("NT_INFIMUMBLIMIT")					// 下确界
#define NT_INFIMUMBSCRIPT				_T("NT_INFIMUMBSCRIPT")					// 下确界

#define NT_TOPBOTTOM					_T("NT_TOPBOTTOM")
#define NT_LINE							_T("NT_LINE")
#define NT_FRACTION						_T("NT_FRACTION")						// x over y

#define NT_MATRIX						_T("NT_MATRIX")							// matrix
#define NT_HORIZONTALMATRIX				_T("NT_HORIZONTALMATRIX")				// Horizontal matrix
#define NT_VERTICALMATRIX				_T("NT_VERTICALMATRIX")					// Vertical matrix

#define NT_RIGHTSINGLEARROW				_T("NT_RIGHTSINGLEARROW")				// arrow
#define NT_LEFTSINGLEARROW				_T("NT_LEFTSINGLEARROW")				// arrow
#define NT_TWOWAYSINGLEARROW			_T("NT_TWOWAYSINGLEARROW")				// arrow
#define NT_RIGHTHALFARROW				_T("NT_RIGHTHALFARROW")					// arrow
#define NT_LEFTHALFARROW				_T("NT_LEFTHALFARROW")					// arrow
#define NT_TWOWAYHALFARROW				_T("NT_TWOWAYHALFARROW")				// arrow
#define NT_RIGHTDOUBLEARROW				_T("NT_RIGHTDOUBLEARROW")				// arrow
#define NT_LEFTDOUBLEARROW				_T("NT_LEFTDOUBLEARROW")				// arrow
#define NT_TWOWAYDOUBLEARROW			_T("NT_TWOWAYDOUBLEARROW")				// arrow

#define NT_TOPRIGHTSINGLEARROW			_T("NT_TOPRIGHTSINGLEARROW")			// tagged sign
#define NT_TOPLEFTSINGLEARROW			_T("NT_TOPLEFTSINGLEARROW")				// tagged sign
#define NT_TOPRIGHTHALFARROW			_T("NT_TOPRIGHTHALFARROW")				// tagged sign
#define NT_TOPLEFTHALFARROW				_T("NT_TOPLEFTHALFARROW")				// tagged sign
#define NT_TOPTWOWAYSINGLEARROW			_T("NT_TOPTWOWAYSINGLEARROW")			// tagged sign
#define NT_TOPONEPOINT					_T("NT_TOPONEPOINT")					// tagged sign
#define NT_TOPTWOPOINT					_T("NT_TOPTWOPOINT")					// tagged sign
#define NT_TOPTHREEPOINT				_T("NT_TOPTHREEPOINT")					// tagged sign
#define NT_TOPONELINE					_T("NT_TOPONELINE")						// tagged sign
#define NT_TOPTWOLINE					_T("NT_TOPTWOLINE")						// tagged sign
#define NT_TOPACUTEACCENT				_T("NT_TOPACUTEACCENT")					// 锐音符
#define NT_TOPGRAVEACCENT				_T("NT_TOPGRAVEACCENT")					// 抑音符
#define NT_TOPCIRCUMFLEXACCENT			_T("NT_TOPCIRCUMFLEXACCENT")			// 抑扬符
#define NT_TOPMODULATEACCENT			_T("NT_TOPMODULATEACCENT")				// 修饰字母抑扬符
#define NT_TOPTILDE						_T("NT_TOPTILDE")						// ~
#define NT_TOPBREVEACCENT				_T("NT_TOPBREVEACCENT")					// 短音符号

#define NT_PRODUCT						_T("NT_PRODUCT")						// product
#define NT_PRODUCTTBLIMIT				_T("NT_PRODUCTTBLIMIT")					// product
#define NT_PRODUCTTBSCRIPT				_T("NT_PRODUCTTBSCRIPT")				// product
#define NT_PRODUCTBLIMIT				_T("NT_PRODUCTBLIMIT")					// product
#define NT_PRODUCTBSCRIPT				_T("NT_PRODUCTBSCRIPT")					// product
#define NT_ACCESSORYPRODUCT				_T("NT_ACCESSORYPRODUCT")				// accessoryproduct
#define NT_ACCESSORYPRODUCTTBLIMIT		_T("NT_ACCESSORYPRODUCTTBLIMIT")		// accessoryproduct
#define NT_ACCESSORYPRODUCTTBSCRIPT		_T("NT_ACCESSORYPRODUCTTBSCRIPT")		// accessoryproduct
#define NT_ACCESSORYPRODUCTBLIMIT		_T("NT_ACCESSORYPRODUCTBLIMIT")			// accessoryproduct
#define NT_ACCESSORYPRODUCTBSCRIPT		_T("NT_ACCESSORYPRODUCTBSCRIPT")		// accessoryproduct
#define NT_UNION						_T("NT_UNION")							// union
#define NT_UNIONTBLIMIT					_T("NT_UNIONTBLIMIT")					// union
#define NT_UNIONTBSCRIPT				_T("NT_UNIONTBSCRIPT")					// union
#define NT_UNIONBLIMIT					_T("NT_UNIONBLIMIT")					// union
#define NT_UNIONBSCRIPT					_T("NT_UNIONBSCRIPT")					// union
#define NT_INTERSECTION					_T("NT_INTERSECTION")					// intersection
#define NT_INTERSECTIONTBLIMIT			_T("NT_INTERSECTIONTBLIMIT")			// intersection
#define NT_INTERSECTIONTBSCRIPT			_T("NT_INTERSECTIONTBSCRIPT")			// intersection
#define NT_INTERSECTIONBLIMIT			_T("NT_INTERSECTIONBLIMIT")				// intersection
#define NT_INTERSECTIONBSCRIPT			_T("NT_INTERSECTIONBSCRIPT")			// intersection

#define NT_SIN							_T("NT_SIN")							// sinx
#define NT_COS							_T("NT_COS")							// cosx
#define NT_TAN							_T("NT_TAN")							// tanx
#define NT_CSC							_T("NT_CSC")							// cscx
#define NT_SEC							_T("NT_SEC")							// secx
#define NT_COT							_T("NT_COT")							// cotx

#define NT_ARCSIN						_T("NT_ARCSIN")							// arcsinx
#define NT_ARCCOS						_T("NT_ARCCOS")							// arccosx
#define NT_ARCTAN						_T("NT_ARCTAN")							// arctanx

#define NT_SINH							_T("NT_SINH")							// sinhx
#define NT_COSH							_T("NT_COSH")							// coshx
#define NT_TANH							_T("NT_TANH")							// tanhx
#define NT_COTH							_T("NT_COTH")							// cothx

#define NT_ARG							_T("NT_ARG")							// arg
#define NT_DEG							_T("NT_DEG")							// deg
#define NT_DET							_T("NT_DET")							// det
#define NT_DIM							_T("NT_DIM")							// dim
#define NT_EXP							_T("NT_EXP")							// exp
#define NT_GCD							_T("NT_GCD")							// gcd
#define NT_HOM							_T("NT_HOM")							// hom
#define NT_KER							_T("NT_KER")							// ker
#define NT_PR							_T("NT_PR")								// pr
#define NT_LIMINF						_T("NT_LIMINF")							// liminf
#define NT_LIMSUP						_T("NT_LIMSUP")							// limsup

#define NT_INVERSE						_T("NT_INVERSE")						// inverse

//Word英文默认为Calibri (西文正文)，通常在自然科学或工程技术中用于符号的一般为Times New Roman，斜体。
const TCHAR* const kFontFamily = _T("微软雅黑");
const TCHAR* const kFontFamily_Number = _T("Arial");
const TCHAR* const kFontFamily_GreekAlphabet = _T("Symbol");
const TCHAR* const kFontFamily_Character = _T("Times New Roman");
const TCHAR* const kFontFamily_Handwriting = _T("Lucida Calligraphy");
const TCHAR* const kFontFamily_Copperplate = _T("Euclid Fraktur");
const TCHAR* const kFontFamily_Cambria = _T("Cambria");
const TCHAR* const kFontFamily_Song = _T("宋体");
const UINT kFontSize = 24;
const COLORREF kNodeColor = 0xFF000000;

#define MAX_FORMULA_TEXT_LENGTH 2048

LPCTSTR GetOperatorTextByNodeType(LPCTSTR strNodeType);

class CNode
{
public:
	CNode();
	CNode(LPCTSTR strNodeType, LPCTSTR strText, COLORREF crColor = kNodeColor, int iFontSize = kFontSize);
	virtual ~CNode();

	CNode(const CNode& src);
	CNode& operator=(const CNode& other);
	bool operator==(const CNode& other);

	static CNode* dynamicCopyNode(const CNode& other);
	static CNode* dynamicCreateNode(LPCTSTR strNodeType, LPCTSTR strText);

	void construct();

	// Hit-Test codes
	enum TrackerHit
	{
		hitNothing = -1, hitLeftChild = 0, hitRightChild = 1, hitMiddle = 2,
	};

	// pointer to parent
	CNode* m_pParent;
	// pointer to left child
	CNode* m_pLeftChild;
	// pointer to right child
	CNode* m_pRightChild;

	// Returns the node type
	LPCTSTR GetNodeType();

	// Sets the parent node directly
	void SetParentNode(CNode* pNode);
	// Returns the parent node
	CNode* GetParentNode();

	// Sets the left child (and sets left child's new parent as this)
	void SetLeftChild(CNode* pNode);
	// Returns the left child
	CNode* GetLeftChild();

	// Sets the right child (and sets right child's new parent as this)
	void SetRightChild(CNode* pNode);
	// Returns the right child
	CNode* GetRightChild();

	bool IsLeftChild();
	bool IsRightChild();
	// Returns the brother node
	CNode* GetBrotherNode();

	// Sets the text of the node (used for rendering)
	void SetText(LPCTSTR strText);
	// Returns the text of the node
	LPCTSTR GetText();

	// Sets the edit mode of the node
	void SetEditMode(bool bEditMode);
	// Returns the edit mode of the node
	bool GetEditMode();

	bool GetDelMode();

	// Sets the RGB colour of the node
	void SetColor(COLORREF crColor);
	// Returns the RGB colour of the node
	COLORREF GetColor();
	virtual void ChangeColor(COLORREF crColor);//影响子节点

	//Sets the minimum width of the node
	void SetMinWidth(int iMinWidth);

	// Sets the facename in the LOGFONT structure
	void SetFaceName(LPCTSTR strFaceName);
	// Returns the facename of the LOGFONT structure as a CString
	LPCTSTR GetFaceName();

	// Returns a pointer to the LOGFONT structure m_lf
	LOGFONT* GetLogFont();

	void SetFontSize(int iFontSize);//不影响子节点
	int GetFontSize();
	virtual void ChangeFontSize(int iFontSize);//影响子节点

	// Returns TRUE if the node has no valid left and right child
	virtual BOOL IsNodeLeaf();

	RECT GetRect();
	void SetRect(LPRECT lprc);

	SIZE GetTextSize() const;

	POINT GetBaseline() const;
	LONG GetBaselineY() const;

	DWORD GetWidth() const;
	DWORD GetHeight() const;

	LPCTSTR GetFaceNameByNodeType(LPCTSTR strNodeType);
	void InitTEXTMERTIC();

	void UpdateTextSize();
	virtual void UpdateRect();
	virtual void TranslateRect(int iTranslateX, int iTranslateY);//上下左右平移

	virtual void ExtendBorderByChild();//根据孩子节点的边界延伸边界（带递归子节点）

	CNode* GetMatrixRootNode();//获取矩阵的根节点
	virtual int GetMatrixRows();//获取矩阵的行数
	virtual int GetMatrixColumn();//获取矩阵的列数

	// drawing functions
	virtual void DrawNode(Gdiplus::Graphics* pGraphics);
	void DrawNodeText(Gdiplus::Graphics* pGraphics, POINT pt);
	//void DrawImage(Graphics* pGraphics, );
	void DrawNodeRegion(Gdiplus::Graphics* pGraphics, bool bShowBorder = false);
	void DrawLine(Gdiplus::Graphics* pGraphics, POINT pt1, POINT pt2, UINT iPenWidth = 0);
	void DrawArrow(Gdiplus::Graphics* pGraphics, POINT pt1, POINT pt2, double theta, int length, float fPenWidth, COLORREF color, bool bTop = true, bool bBottom = true);
	void DrawDoubleArrow(Gdiplus::Graphics* pGraphics, POINT pt1, POINT pt2, double theta, int length, int offset, float fPenWidth, COLORREF color);

	virtual CNode* GetNodeFromPoint(POINT pt);

	CNode* GetLeftJointNode(bool bDelMode = false);//获取左侧相邻的可编辑节点（bDelMode用于是否遍历分式等借助占位节点的孩子）
	CNode* GetRightJointNode(bool bDelMode = false);//获取右侧相邻的可编辑节点（bDelMode用于是否遍历分式等借助占位节点的孩子）
	CNode* GetLeftEditNode(CNode* pNode, bool bDelMode = false);//获取最左边的第一个编辑节点（bDelMode用于是否遍历分式等借助占位节点的孩子）
	CNode* GetRightEditNode(CNode* pNode, bool bDelMode = false);//获取最右边的第一个编辑节点（bDelMode用于是否遍历分式等借助占位节点的孩子）
	CNode* GetFarLeftChild();//获取最左边的孩子节点
	CNode* GetFarRightChild();//获取最右边的孩子节点
	CNode* GetDelNode();//获取需要删除的节点

	virtual int HitTest(POINT point);
	virtual void save(LPTSTR strFormulaText);
	static CNode* load(LPCTSTR strFormulaText);
protected:
	// Node is allowed or not allowed to be edited
	bool m_bEditMode;

	bool m_bDelMode;//是否可以通过子节点来删除

	bool m_bLeftPart;
	bool m_bRightPart;

	// node type (one of the NT_* defines)
	TCHAR m_strNodeType[MAX_PATH];
	// the shortcut of the node (sin for sinus)
	TCHAR m_strText[MAX_PATH];
	// color of the node (modified by the formatter class)
	COLORREF m_crColor;
	// LOGFONT node (modified by the formatter class)
	LOGFONT m_lf;

	SIZE m_szText;
	// the destination rectangle for the ouput
	RECT m_rcNode;

	UINT m_iFontSize;

	bool m_btmInternalLeading;
	bool m_btmDescent;
	TEXTMETRIC m_tm;
	POINT m_ptBaseline;

	int m_iMinWidth;
	int m_iLeftChildMinWidth;
	int m_iRightChildMinWidth;

	virtual void TranslateChildRectToTopLeft();//平移孩子区域至左上角

	virtual void UpdateNodeBorder();//根据孩子节点的边界更新边界

	virtual void FormatMatrixRect();//用于矩阵行列的对齐
};
